// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';
import { DistBuildDataManager } from './DataManager';
import { DistBuildTaskProvider } from './DistBuildTaskProvider';
import { DistBuildTreeView } from './DistBuildTreeView';

let extensionPath = ""
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {

	extensionPath = context.extensionPath
	// Use the console to output diagnostic information (console.log) and errors (console.error)
	// This line of code will only be executed once when your extension is activated
	//console.log('Congratulations, your extension "kylin-code-dist-compile" is now active!');

	// The command has been defined in the package.json file
	// Now provide the implementation of the command with registerCommand
	// The commandId parameter must match the command field in package.json
	/*
	let disposable = vscode.commands.registerCommand('kylin-code-dist-compile.helloWorld', () => {
		// The code you place here will be executed every time your command is executed
		// Display a message box to the user
		vscode.window.showInformationMessage('Hello World from kylin-code-dist-compile!');
	});
	context.subscriptions.push(disposable);
	vscode.commands.getCommands().then(cmds => {
		cmds.forEach(c => {
			if (c.startsWith("workbench.action.tasks")) {
				console.log(c)
			}
		})
	})
	*/

	let distTaskProvider = vscode.tasks.registerTaskProvider(DistBuildTaskProvider.type, new DistBuildTaskProvider(context));
	context.subscriptions.push(distTaskProvider);

	let treeView = new DistBuildTreeView(context);
	let distTreeView = vscode.window.registerTreeDataProvider(DistBuildTreeView.viewId, treeView);
	vscode.commands.registerCommand("distbuild.addHost", () => treeView.add());
	vscode.commands.registerCommand("distbuild.runTask", () => treeView.runTask());
	vscode.commands.registerCommand("distbuild.refresh", () => treeView.refresh());
	vscode.commands.registerCommand("distbuild.remove", (theNode: any) => treeView.remove(theNode));
	vscode.commands.registerCommand("distbuild.stop", (theNode: any) => treeView.stop(theNode));
	vscode.commands.registerCommand("distbuild.run", (theNode: any) => treeView.run(theNode));
	context.subscriptions.push(distTreeView);
}

// this method is called when your extension is deactivated
export function deactivate() {
	DistBuildDataManager.getInstance(extensionPath).storage()
}
